/// select()的参数的FdSet结构
pub type FdSet = windows_sys::Win32::Networking::WinSock::FD_SET;
/// select()的参数的Timeval结构
pub type Timeval = windows_sys::Win32::Networking::WinSock::TIMEVAL;

/// 确定一个或多个套接字的状态（如有必要）等待执行同步I/O
#[inline(always)]
pub fn select(nfds: i32, readfds: *mut FdSet, writefds: *mut FdSet, errorfds: *mut FdSet, timeout: *mut Timeval) -> i32
{
    unsafe { windows_sys::Win32::Networking::WinSock::select(nfds, readfds, writefds, errorfds, timeout) }
}
/// 将感兴趣的套接字描述符加入集合中
pub fn fd_zero(set: *mut FdSet)
{
    unsafe { (*set).fd_count = 0 }
}
/// 将感兴趣的套接字描述符加入集合中
pub fn fd_set(fd: Socket, set: *mut FdSet)
{
    unsafe {
        (*set).fd_array[(*set).fd_count as usize] = fd;
        (*set).fd_count += 1;
    }
}
/// 从集合中移出一个套接口描述符
pub fn fd_clr(fd: Socket, set: *mut FdSet)
{
    unsafe {
        for i in 0..(*set).fd_count
        {
            if (*set).fd_array[i as usize] == fd
            {
                (*set).fd_count -= 1;
                (*set).fd_array[i as usize] = (*set).fd_array[(*set).fd_count as usize];
                return;
            }
        }
    }
}
/// 检查描述符是否在集合中，如果在集合中返回true，否则返回false
pub fn fd_isset(fd: Socket, set: *const FdSet) -> bool
{
    unsafe {
        for i in 0..(*set).fd_count
        {
            if (*set).fd_array[i as usize] == fd
            {
                return true;
            }
        }
        false
    }
}
